package com.open.capacity.finance.controller;


import com.open.capacity.commons.Result;
import com.open.capacity.model.system.SysUser;
import com.open.capacity.utils.SysUserUtil;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.finance.entity.SysUsersettingDefault;
import com.open.capacity.finance.service.SysUsersettingDefaultService;


import javax.validation.Valid;

/**
 * 用户默认参数设置
 *
 * @author
 * @email
 * @date 2020-08-07 09:20:08
 */
@RestController
@RequestMapping("usersettings")
@Api(tags = "用户默认参数设置")
public class SysUsersettingDefaultController {

    @Autowired
    private SysUsersettingDefaultService sysUsersettingDefaultService;


    /**
     * 查询单条记录
     */
    @RequestMapping("/current")
    @PreAuthorize("hasAnyAuthority('setting:default:list')")
    public Result current() {
        SysUser loginUser = SysUserUtil.getLoginAppUser();
        return Result.succeed(sysUsersettingDefaultService.findById(loginUser.getId()));
    }


    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('setting:default:save')")
    public Result save(@RequestBody @Valid SysUsersettingDefault sysUsersettingDefault, String keyValue) {
        sysUsersettingDefaultService.saveOrUpdate(sysUsersettingDefault);
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('setting:sysusersettingdefault:delete')")
    public Result delete(@PathVariable String id) {
        sysUsersettingDefaultService.delete(id);
        return Result.succeed("删除成功");
    }

}
